#include<iostream>

using namespace std;

class Solution {
public:
    int firstUniqChar(string s) {
        int begin = 0;
        int end = s.size() - 1;
        while (begin <= end)
        {
            int left, right;
            left  = begin-1;
            right = begin + 1;
            int flag = 0;
            while (left >= 0)
            {
                if (s[left] == s[begin])
                {
                    flag = 1;
                    break;    
                }
                left--;

            }
            while (right <= end && flag == 0)
            {
                if (s[right] == s[begin])
                {
                    flag = 1;
                    break;
                }
                right++;
            }
            if (flag == 0)return begin;
            begin++;
        }
        return -1;
    }
};


class Solution2
{
public:
    int firstUniqChar(string s)
    {
        int index1; int index2;
        for (int i = 0; i < s.size(); i++)
        {
            index1 = s.find(s[i]);
            index2 = s.rfind(s[i]);
            if (index1 == index2)return index1;
        }
        return -1;
    }
};